/*
   Copyright 2009 adamrocker

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

// ResultDialog.java
package jp.ne.iforce.android.wifioffload;

import static jp.ne.iforce.android.wifioffload.BarCodeActivity.TAG;
import jp.ne.iforce.android.wifioffload.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.zxing.Result;

public class ResultDialog extends Dialog
    implements android.view.View.OnClickListener {


//    private ImageView mResultImg;
    private TextView mNumTextView;
    private TextView mFormatTextView;
    private Button mAccessBtn;
    private Button mCancelBtn;
    // private Bitmap img;
    private BarCodeActivity barCodeActivity;

    public ResultDialog(Context context) {
        super(context);
        barCodeActivity = (BarCodeActivity) context;

        setContentView(R.layout.result_dialog);

        //mResultImg = (ImageView) findViewById(R.id.result_img);
        mFormatTextView = (TextView) findViewById(R.id.format_txt);
        mNumTextView = (TextView) findViewById(R.id.num_txt);
        mCancelBtn = (Button) findViewById(R.id.cancel_btn);
        mCancelBtn.setOnClickListener(this);
        mAccessBtn = (Button) findViewById(R.id.access_btn);
        mAccessBtn.setOnClickListener(this);

        setTitle(R.string.result_title);
        //mResultImg.setImageBitmap(img);
    }

    void set(Result result) {
        Log.i(TAG, "set");
        String format = result.getBarcodeFormat().toString();
        String num = result.getText();

        mNumTextView.setText(num);
        mFormatTextView.setText("FORMAT: " + format);
    }

    public void onClick(View v) {
        if (v == mAccessBtn) {
        	barCodeActivity.startSms();
        } else if (v == mCancelBtn) {
            // オートフォーカス開始 / バーコード解析開始
        	barCodeActivity.requestAutoFocus();
            dismiss();
        }
    }


}
